通用权限框架--web 首页
1.首页截图
2.首页views
布局分为三部分top,left,main
引入easyui和jquery的js以及相关的css
使用easyui进行布局,分区代码body设置class="easyui-layout"
<body class="easyui-layout" >
<div region="north" id="">top</div>
<div region="west" id="">left部分</div>
<div region="center" id="">main</div>
</body>
3.左侧导航菜单js脚本initleftmenu()
$(document).ready(function () { InitLeftMenu(); tabClose(); tabCloseEven(); passwordclose();});//初始化左侧function InitLeftMenu() { $("#nav").accordion({ animate: false }); $.getJSON('/Home/InitMenu', function (msg) { $.each(msg.menus, function (i, n) { var menulist = ''; menulist += '
- '; $.each(n.menus, function (j, o) { menulist += '
- '; }) menulist += '
4.首页HomeController
主要是初始化左侧导航菜单
public class HomeController : Controller { public ActionResult Index() { return View(); } public ActionResult InitMenu() { //Session["login_id"] = "0001"; //c测试 string userid = ""; if (Session["login_id"] != null && Session["login_prms"] != null) { userid = Session["login_id"].ToString(); Dictionarylogin_prms = new Dictionary (); login_prms = (Dictionary )Session["login_prms"]; var result = new G_menuRepository().LoadEntities(a => a.isshow == 0 && login_prms.Keys.Contains(a.id)).ToList(); IG_menuRepository repository = RepositoryFactory.G_menuRepository; repository.SetLazyLoading(false); return Content("{\"menus\":[" + GetMenu(result, 0, login_prms).Trim(',') + "]}"); } else { return Content("logout"); } } public string GetMenu(List result, int id, Dictionary login_prms) { StringBuilder sb = new StringBuilder(); string parentmenu = "", submenu = ""; foreach (var rs1 in result.Where(p => p.parentid == id)) { parentmenu = ("{\"menuid\":\"" + rs1.menuid + "\",\"icon\":\"" + rs1.icon + "\",\"menuname\":\"" + rs1.menuname + "\",\"prms\":\"" + login_prms[rs1.id].ToString() + "\",\"link\":\"" + rs1.link + "\""); submenu = GetMenu(result, rs1.id, login_prms); if (string.IsNullOrEmpty(submenu)) { sb.Append(((parentmenu + ",\"menus\":[" + submenu).Trim(',')) + "]},"); } else { sb.Append(((parentmenu + ",\"menus\":[" + submenu).Trim(',')) + "]},"); } } return sb.ToString(); } }
初始化导航菜单返回json格式如下
{ "menus": [ { "menuid": "11", "icon": "icon icon-nav", "menuname": "系统管理", "prms": "1", "link": "", "menus": [ { "menuid": "1101", "icon": "icon icon-Pass", "menuname": "组织机构", "prms": "2,3,4", "link": "/orga", "menus": [] }, { "menuid": "1102", "icon": "icon icon-set", "menuname": "导航菜单", "prms": "2,3,4", "link": "/menu", "menus": [] }, { "menuid": "1104", "icon": "icon icon-sys", "menuname": "操作权限", "prms": "2,3,4", "link": "/prms", "menus": [] }, { "menuid": "1105", "icon": "icon icon-users", "menuname": "角色管理", "prms": "2,3,4,5", "link": "/role", "menus": [] }, { "menuid": "1206", "icon": "icon icon-role", "menuname": "用户管理", "prms": "2,3,4", "link": "/grantuser", "menus": [] } ] }, { "menuid": "16", "icon": "icon icon-delete", "menuname": "业务管理", "prms": "1", "link": "", "menus": [] } ]}